<template>
  <el-container class="right-panel-container">
    <SettingDialog v-model="showSettings" />
    <!-- 顶部导航栏 -->
    <el-header class="nav-toolbar">
      <div class="header-content">
        <div class="logo-section" @click="toggleHistory">
          <el-icon class="logo-icon" size="24">
            <ChatRound />
          </el-icon>
          <h1 class="panel-title">AI对话助手</h1>
        </div>

        <!-- 右侧操作按钮 -->
        <div class="action-buttons">
          <!-- 模型选择下拉列表 -->
          <el-select
              v-model="selectedModel"
              placeholder="选择模型"
              size="small"
              class="model-select"
          >
            <el-option label="默认模型" value="default"></el-option>
            <el-option label="高级模型" value="advanced"></el-option>
            <el-option label="快速响应模型" value="fast"></el-option>
          </el-select>

          <el-button
              class="custom-btn"
              size="small"
              @click="toggleHistory"
          >
            <Clock class="icon" />
            <span class="btn-text">历史</span>
          </el-button>

          <el-button
              class="custom-btn"
              size="small"
              @click="showSettings = true"
          >
            <Setting class="icon" />
            <span class="btn-text">对话设置</span>
          </el-button>
        </div>
      </div>
    </el-header>


    <el-main class="main-content">
      <div class="content-wrapper">
        <!-- 主对话容器（关键：让子组件自己处理滚动） -->
        <div class="dialogue-container">
          <AIDialogue />
        </div>

        <!-- 历史记录侧边栏（动画优化版） -->
        <transition-group name="sidebar" class="history-sidebar-group">
          <div
              v-if="showHistory"
              class="history-sidebar"
              key="sidebar"
          >
            <h3>对话历史</h3>
            <!-- 可扩展对话历史列表 -->
            <div class="history-list">
              <div
                  v-for="(item, index) in 5"
                  :key="index"
                  class="history-item"
                  :class="{ active: index === 0 }"
              >
                对话{{ index + 1 }}
              </div>
            </div>
          </div>
        </transition-group>
      </div>
    </el-main>
  </el-container>
</template>

<script setup>
import { ref } from 'vue';
import AIDialogue from "@/views/AIDialogue.vue";
import { ChatRound, Setting, Clock } from '@element-plus/icons-vue';
import SettingDialog from "@/components/SettingDialog.vue";

// 状态管理
const showSettings = ref(false);
const showHistory = ref(false);
const selectedModel = ref('default');

// 侧边栏toggle逻辑收敛
const toggleHistory = () => {
  showHistory.value = !showHistory.value;
};
</script>

<style scoped>
/* ====================== 基础变量定义 ====================== */
:root {
  --primary-color: #409eff;
  --bg-color: #f7f8fa;
  --sidebar-width: 280px;
  --transition-base: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ====================== 布局容器 ====================== */
.right-panel-container {
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden; /* 锁定整体布局，防止意外溢出 */
}

/* ====================== 顶部导航栏 ====================== */
.nav-toolbar {
  background: #fff;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.03);
  height: 64px;
  padding: 0 24px;
  display: flex;
  align-items: center;
  z-index: 10;
}

.header-content {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.logo-section {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  transition: transform var(--transition-base);
}

.logo-section:hover {
  transform: scale(1.02);
}

.logo-icon {
  color: var(--primary-color);
  transition: transform 0.3s ease, color 0.3s ease;
}

.logo-section:hover .logo-icon {
  transform: scale(1.1) rotate(5deg);
  color: #6aa8ff;
}

.panel-title {
  font-size: 18px;
  font-weight: 600;
  margin: 0;
  background: linear-gradient(90deg, #409eff, #67c23a);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

/* ====================== 操作按钮 ====================== */
.action-buttons {
  display: flex;
  align-items: center;
  gap: 12px;
}

.model-select {
  width: 140px;
  margin-right: 8px;
}

.custom-btn {
  padding: 8px 14px;
  font-size: 14px;
  border-radius: 6px;
  transition: all var(--transition-base);
  display: flex;
  align-items: center;
  gap: 6px;
  background-color: #f5f7fa;
  border: 1px solid #e4e7ed;
  color: #606266;
}

.custom-btn:hover {
  background-color: #eef2f7;
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
  border-color: #dcdfe6;
}

.custom-btn .icon {
  width: 16px;
  height: 16px;
}

/* ====================== 主内容区 ====================== */
.main-content {
  flex: 1;
  background-color: var(--bg-color);
  overflow: hidden; /* 让子组件自己处理滚动 */
  position: relative;
}

.content-wrapper {
  display: flex;
  width: 100%;
  height: 100%;
}

/* 主对话容器（关键：让子组件占满空间） */
.dialogue-container {
  flex: 1;
  padding: 24px;
  min-width: 0;
  overflow: hidden;
}

/* ====================== 历史侧边栏（动画优化版） ====================== */
.history-sidebar-group {
  position: relative;
  width: var(--sidebar-width);
  flex-shrink: 0;
}

.history-sidebar {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: var(--sidebar-width);
  background-color: #fff;
  border-left: 1px solid #e5e7eb;
  box-shadow: -2px 0 10px rgba(0, 0, 0, 0.03);
  overflow-y: auto;
  transform: translateX(-100%); /* 初始隐藏 */
  transition: transform var(--transition-base), box-shadow var(--transition-base);
}

.history-sidebar.show-sidebar {
  transform: translateX(0);
  box-shadow: 0 0 20px rgba(0, 0, 0, 0.05);
}

.history-sidebar h3 {
  padding: 20px;
  margin: 0;
  font-size: 16px;
  color: #303133;
  border-bottom: 1px solid #e5e7eb;
}

.history-list {
  padding: 15px 0;
}

.history-item {
  padding: 12px 20px;
  cursor: pointer;
  transition: all var(--transition-base);
  color: #606266;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-item:hover {
  background-color: #f5f7fa;
  color: var(--primary-color);
}

.history-item.active {
  background-color: #eef5ff;
  color: var(--primary-color);
  font-weight: 500;
}

/* ====================== 滚动条美化（公共类） ====================== */
.scrollbar::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

.scrollbar::-webkit-scrollbar-track {
  background: transparent;
}

.scrollbar::-webkit-scrollbar-thumb {
  background-color: rgba(156, 163, 175, 0.5);
  border-radius: 3px;
  transition: background-color var(--transition-base);
}

.scrollbar::-webkit-scrollbar-thumb:hover {
  background-color: rgba(156, 163, 175, 0.8);
}

/* ====================== 响应式优化 ====================== */
@media (max-width: 768px) {
  .nav-toolbar {
    padding: 0 16px;
  }

  .panel-title {
    font-size: 16px;
  }

  .history-sidebar {
    position: fixed;
    top: 64px;
    left: 0;
    z-index: 100;
  }
}
</style>